package com.learn.sb.rabbitmq.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.learn.sb.rabbitmq.service.RabbitMqService;

import pojo.User;

@RestController
@RequestMapping("/rabbitmq")
public class RabbitMqController {
	@Autowired
	private RabbitMqService rabbitMqService;

	@GetMapping("/msg")
	public Map<String, Object> msg(String msg) {
		rabbitMqService.sendMsg(msg);
		return resultMap("msg", msg);
	}

	@GetMapping("/user")
	public Map<String, Object> user(Long id, String userName, String note) {
		User user = new User(id, userName, note);
		rabbitMqService.sendUser(user);
		return resultMap("user", user);
	}

	private Map<String, Object> resultMap(String key, Object obj) {
		Map<String, Object> map = new HashMap<>();
		map.put("success", true);
		map.put(key, obj);
		return map;
	}
}
